﻿using AMAP.Domain;
using AMAP.ServiceClasses.Common;
using AMAP.ServiceInterfaces;
using AMAP.ServiceInterfaces.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace AMAP.ServiceClasses
{
    public class SubscriptionService : BaseRepositoryService<Subscription>, ISubscriptionService
    {
        public SubscriptionService(IDatabaseFactory databaseFactory)
            : base(databaseFactory)
        {
        }

        public Subscription GetLast(int ClientId)
        {
            return this.dataContext.SubscriptionSet.Where(s => s.ClientId == ClientId).OrderByDescending(s => s.Id).FirstOrDefault();
        }

        public IList<Subscription> GetCurrentWeekList()
        {
            int QuarterIndex = (int)(Thread.CurrentThread.CurrentCulture.Calendar.GetMonth(DateTime.Now) / 3);

            return this.dataContext.SubscriptionSet.Where(s => s.Quarter.Year == DateTime.Now.Year && s.Quarter.Index == QuarterIndex).ToList<Subscription>();
        }
    }
}
